<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <title>提现</title>
    <link rel="stylesheet" href="css/reset.css">
    <link rel="stylesheet" href="css/jiazai.css">
    <style>
        .hea-con {
            padding: 10px 20px 0;
            font-size: 16px;
            color: white;
            opacity: .7;
        }
        
        .input-wrap {
            padding: 20px;
            box-sizing: border-box;
        }
        
        .input-wrap>input {
            width: 100%;
            box-sizing: border-box;
            padding: 15px 10px;
            margin-top: 15px;
            font-size: 16px;
            color: white;
            background: #353742;
            border-radius: 5px;
        }
        
        .input-wrap>p {
            margin-top: 25px;
            padding: 16px;
            text-align: center;
            font-size: 18px;
            color: rgba(255, 255, 255, .6);
            background: #353742;
            border-radius: 5px;
        }
        
        .invi-code {
            padding: 15px 10px;
            margin-top: 15px;
            font-size: 16px;
            color: rgba(255, 255, 255, .6);
            background: #353742;
            border-radius: 5px;
        }
        
        .invi-code>input {
            flex: 1 1 0;
            width: 100%;
            color: white;
            background: transparent;
        }
        
        .invi-code>span {
            flex: 0 0 80px;
            font-size: 13px;
            text-align: right;
            opacity: .7;
        }
    </style>
</head>

<body style="background:#2a2c35;">
    <div id='app'>


        <!-- 加载中动画 -->
        <div id='jiazai-ani' v-if='jiazai'>
            <div class="arc"></div>
            <h1><span>LOADING</span></h1>
        </div>
        <!-- 加载中动画 -->

        <div class='hea-con dis-spa'>
            <img @click='_close()' src="./img/left.svg" width="22px" height="22px">
            <span>
                提现
            </span>
            <span style="opacity:0">1</span>
        </div>

        <div class='input-wrap'>
            <input type="text" placeholder="请输入提现地址或账户" v-model='send.send_to'>
            <div class='invi-code dis-spa'>
                <input type="text" placeholder="提现额度" v-model='send.amount'>
                <span>cc个数</span>
            </div>
            <input type="text" placeholder="备注(不可超过20字)" v-model='send.msg'>
            <p @click='openPay' :style="{'background':(send.amount&&send.send_to)?'#2590FE':''}">立即提现</p>
        </div>
    </div>
    <script src="js/comm.js"></script>
    <script src="js/vue.min.js"></script>
    <script src="js/jquery.min.js"></script>
    <script>
        var app = new Vue({
            el: '#app',
            data: {
                jiazai: false,
                //输入数据
                send: {
                    send_to: '',
                    //数量
                    amount: '',
                    //备注
                    msg: '',
                    //余额等信息
                    money: {}
                },
                //false:没设置交易密码  true:设置了交易密码
                setPas: true,
            },
            created: function() {
                var This = this;
                var user = JSON.parse(localStorage.getItem('cc_user'));
                _post(TIXIAN_INDEX, {
                    userid: user.userid,
                    session: user.session
                }, function(data) {
                    This.jiazai = false;
                    This.money = data.back;
                });
                this.myIndex();
            },
            methods: {
                //看设置交易密码与否
                myIndex: function() {
                    var This = this;
                    var user = JSON.parse(localStorage.getItem('cc_user'));
                    _post(MY_INDEX, {
                        userid: user.userid,
                        session: user.session,
                    }, function(data) {
                        if (data.status == 1) {
                            if (data.back.is_pin == 1) {
                                //没设置交易密码
                                This.setPas = false;
                            }
                        }
                    })
                },
                openPay: function() {
                    var This = this;
                    if (!this.setPas) {
                        plus.nativeUI.confirm("还没设置交易密码，需要去设置吗?", function(e) {
                            if (!e.index) {
                                _openHref({
                                    url: 'no-trans-pas.html',
                                    id: 'noTransPas'
                                });
                            }
                        });
                        return;
                    }
                    if (!this.send.send_to) {
                        _toast('请输入提现地址');
                        return;
                    }
                    var str = String(parseFloat(this.send.amount)).toLowerCase();
                    if (str == 'nan' || str.length != this.send.amount.length || parseFloat(this.send.amount) <= 0) {
                        _toast('请输入正确的提现数量');
                        this.send.amount = '';
                        return;
                    }
                    if (this.send.msg.length > 20) {
                        _toast('备注不可超过20字');
                        return;
                    }
                    if (parseFloat(this.send.amount) > parseFloat(this.money.regularmoney)) {
                        _toast('余额不足');
                        return;
                    }
                    var curr = plus.webview.currentWebview();
                    curr.setStyle({
                        mask: 'rgba(0,0,0,0.5)'
                    });
                    curr.addEventListener('maskClick', function() {
                        plus.webview.currentWebview().setStyle({
                            mask: 'none'
                        });
                        web.close('none');
                    }, false);

                    //打开输入密码页面
                    var op = {
                        'backButtonAutoControl': 'close', //返回是关闭当前页
                        'animationOptimization': 'none', //不优化
                        'background': 'transparent'
                    };
                    this.jiazai = true;
                    var web = plus.webview.create('input-password.html', 'inputPassword', op);
                    web.addEventListener("loaded", function() {
                        setTimeout(function() {
                            web.evalJS("send('" + TIXIAN_PAY + "','" + JSON.stringify(This.send) + "')");
                            This.jiazai = false;
                            web.show('fade-in');
                        }, 200);
                    }, false);
                    web.onclose = function() {
                        var all = plus.webview.all();
                        for (var i = 0; i < all.length; i++) {
                            all[i].setStyle({
                                mask: 'none'
                            });
                        }
                    };
                }
            }
        });
    </script>
</body>

</html>